package com.junchenrobot.mes.client;

import com.junchenrobot.mes.api.KCApi;
import com.junchenrobot.mes.dto.ResponseDto;
import com.junchenrobot.mes.dto.param.*;
import com.junchenrobot.mes.dto.response.VehicleStatusListDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * kc 客户端
 *
 * @author SeaWave
 * @date 2022/11/12
 */
@Component("kcClient")
public class KCClient {
    
    private final KCApi kcApi;
    
    @Autowired
    public KCClient(KCApi kcApi) {
        this.kcApi = kcApi;
    }
    
    
    /**
     * 添加移动任务
     * 单纯的移动车到指定位置
     *
     * @param taskParam 任务参数
     * @return {@link ResponseDto}
     */
    public ResponseDto addMoveTask(TaskParam taskParam) {
        MoveTaskParam moveTaskParam = MoveTaskParam.builder()
                                                   .taskNo(taskParam.getTaskCode())
                                                   .priority(taskParam.getPriority())
                                                   .vehicleNo(taskParam.getVehicleNo())
                                                   .location(taskParam.getLocation())
                                                   .finishAction(taskParam.getFinishAction())
                                                   .build();
        return kcApi.addMoveTask(moveTaskParam);
    }
    
    
    /**
     * 添加常规任务
     * 任务有任务模板 按照任务模板进行任务
     *
     * @param taskParam 任务参数
     * @return {@link ResponseDto}
     */
    public ResponseDto addRegularTask(TaskParam taskParam) {
        FreeTaskParam freeTaskParam = FreeTaskParam.builder()
                                                   .taskNo(taskParam.getTaskCode())
                                                   .priority(taskParam.getPriority())
                                                   .vehicleNo(taskParam.getVehicleNo())
                                                   .finishAction(taskParam.getFinishAction())
                                                   .location(taskParam.getLocation())
                                                   .taskType(taskParam.getTaskType())
                                                   .unLoadDirection(taskParam.getUnLoadDirection())
                                                   .loadDirection(taskParam.getLoadDirection())
                                                   .build();
        return kcApi.addRegularTask(freeTaskParam);
    }
    
    /**
     * 取消进行中任务
     *
     * @param taskCode 任务编号
     * @return {@link ResponseDto}
     */
    public ResponseDto cancelRunningTask(String taskCode) {
        return kcApi.cancelTask(new TaskCodeParam(taskCode));
    }
    
    /**
     * 暂停进行中任务
     *
     * @param taskCode 任务编号
     * @return {@link ResponseDto}
     */
    public ResponseDto pauseRunningTask(String taskCode) {
        return kcApi.pauseTask(new TaskCodeParam(taskCode));
    }
    
    /**
     * 删除任务
     *
     * @param taskCode 任务编号
     * @return {@link ResponseDto}
     */
    public ResponseDto deleteTask(String taskCode) {
        return kcApi.removeTask(new TaskCodeParam(taskCode));
    }
    
    
    /**
     * 复位设备
     *
     * @param deviceCode 设备编号
     * @return {@link ResponseDto}
     */
    public ResponseDto resetDevice(String deviceCode) {
        return kcApi.resetVehicle(new VehicleCodeParam(deviceCode));
    }
    
    /**
     * 查看所有设备状态
     *
     * @param
     * @return {@link ResponseDto}
     */
    public VehicleStatusListDto vehicleStatus() {
        return kcApi.allVehicleStatus();
    }
    
}
